import java.awt.*;
class TreeDimension extends Dimension
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2497657714110685149L;
	// public int x = 0;
	// public int y = 0;
	public int z = 0;
	
	TreeDimension(int ix, int iy, int iz)
	{
		super(ix,iy);
		// x = ix;
		// y = iy;
		z = iz;
	}
	
	TreeDimension()
	{
		;
	}
	
	TreeDimension(TreeDimension in)
	{
		this(in.width,in.height,in.z);
		/*
		x = in.x;
		y = in.y;
		z = in.z;
		*/
	}
	TreeDimension(Dimension d,int iz)
	{
		this(d.width,d.height,iz);
	}
}

public class Particles implements Runnable 
{
	protected TreeDimension space;
	protected TreeDimension position;
	
	private Thread th;
	
	Particles()
	{
		space = null;
		position = null;
	}
	
	Particles(TreeDimension ispace, TreeDimension pos)
	{
		// space = new TreeDimension(ispace);
		// position = new TreeDimension(pos);
		space = ispace;
		position = pos;
		th = new Thread(this);
		th.start();
	}

	private TreeDimension getRandMove(TreeDimension d)
	{
		double dir;
		
		dir = Math.random();
		if(dir>0.5) d.width+=1;
		else d.width-=1;
		
		if(d.width>space.width) d.width-=2;
		
		if(d.width<0) d.width+=2;
		
		
		dir = Math.random();
		if(dir>0.5) d.height+=1;
		else d.height-=1;
		
		if(d.height>space.height) d.height-=2;
		
		if(d.height<0) d.height+=2;
		
		
		
		dir = Math.random();
		if(dir>0.5) d.z+=1;
		else d.z-=1;
		
		if(d.z>space.z) d.z-=2;
		
		if(d.z<0) d.z+=2;
		
		
		
		
		
		return d;
	}
	
	public void run() 
	{
		while(true) 
		{
			position = getRandMove(position);

			//System.out.println(th.getId()+" "+position.x);
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				
				e.printStackTrace();
			}
		}
	}
}
